<!DOCTYPE html>
<html>

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>flv.js demo</title>
    <style>
        .mainContainer {
    display: block;
    width: 1024px;
    margin-left: auto;
    margin-right: auto;
}

.urlInput {
    display: block;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 8px;
    margin-bottom: 8px;
}

.centeredVideo {
    display: block;
    width: 100%;
    height: 576px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: auto;
}

.controls {
    display: block;
    width: 100%;
    text-align: left;
    margin-left: auto;
    margin-right: auto;
}
    </style>
</head>

<body>
    <div class="mainContainer">
        <video id="videoElement" class="centeredVideo"  autoplay width="1024" height="576" controls="true" controlslist="nodownload">Your browser is too old which doesn't support HTML5 video.</video>
    </div>
    <br>
    <div class="controls">
        <!--<button onclick="flv_load()">加载</button>-->
        <button onclick="flv_start()">开始</button>
        <button onclick="flv_pause()">暂停</button>
        <button onclick="flv_destroy()">停止</button>
        <input style="width:100px" type="text" name="seekpoint" />
        <button onclick="flv_seekto()">跳转</button>
    </div>
    <script src="jquery-1.11.1.min.js"></script>
      <script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.5.0/flv.min.js"></script>
    <script>
        var head=0;
        var player = document.getElementById('videoElement');
        if (flvjs.isSupported()) {
            var flvPlayer = flvjs.createPlayer({
                type: 'mp4',
                url: 'http://localhost:8311/flv/getVideo?token=abcdefgrrrwsdfsdf'
            });
            flvPlayer.attachMediaElement(videoElement);
            flvPlayer.load(); //加载
            $.ajax({
                url:"http://localhost:8311/flv/download",/*url写异域的请求地址*/
                type:"put",
                head:{},
                dataType:"jsonp",/*加上datatype*/
                jsonpCallback:"cb",/*设置一个回调函数，名字随便取，和下面的函数里的名字相同就行*/
                success:function(){
                    console.log("保活成功")
                },
                error(){
                    console.log("保活失败")
                }
            });
            var t2 = window.setInterval(function() {

                console.log("心跳",head++)
                // if(head === 10){
                //     window.clearInterval(t2);
                // }
                $.ajax({
                    url:"http://localhost:8311/flv/video/abcdefgrrrwsdfsdf",/*url写异域的请求地址*/
                    type:"put",
                    dataType:"jsonp",/*加上datatype*/
                    jsonpCallback:"cb",/*设置一个回调函数，名字随便取，和下面的函数里的名字相同就行*/
                    success:function(){
                        console.log("保活成功")
                    },
                    error(){
                        console.log("保活失败")
                    }
                });

            },1000)
        }
       function cb(){

        }
        function flv_start() {
            player.play();
        }

        function flv_pause() {
            player.pause();
        }

        function flv_destroy() {
            player.pause();
            player.unload();
            player.detachMediaElement();
            player.destroy();
            player = null;
        }

        function flv_seekto() {
            player.currentTime = parseFloat(document.getElementsByName('seekpoint')[0].value);
        }
    </script>
</body>

</html>
